
<?php include './application/views/top.php'; ?>
<script src="/static/js/gsdai.js"></script>
<script src="/static/js/ajaxfileupload.js"></script>
<script src="/static/js/My97DatePicker/WdatePicker.js"></script>
<script src="/static/js/formCheck.js"></script>

<div class="clear"></div>
<div class="user_bottom all"></div>
<div class="clear h50"></div>
<div class="layout uc">
	<?php include './application/views/user/left.php'; ?>
	<div class="right">
		<div class="menu_list"><?php include './application/views/user/menu.php'; ?></div>
        <div class="cont">
        	<form id="message_sent_form">
        	<dl class="line">
            	<dt>发送人：</dt>
                <dd><?php echo $user['username']; ?></dd>
            </dl>
        	<dl class="line">
            	<dt>收信人：</dt>
                <dd><input class="input" type="text" id="receive_username" name="receive_username"></dd>
            </dl>
        	<dl class="line">
            	<dt>标题：</dt>
                <dd><input class="input" id="name" type="text" name="name"></dd>
            </dl>

        	<dl class="line">
            	<dt>内容：</dt>
                <dd><textarea id="content" name="content" style="width: 450px;height: 200px;"></textarea></dd>
            </dl>
            <div class="cb"><input class="button" type="submit" value="确认提交" onclick="sent();" /></div>
			</form>
		</div>
	</div>
</div>
<div class="clear h50"></div>
<?php include "./application/views/footer.php";?>
<script>
function sent(){
	var options = {
		url : '/message/dosent',
		clearForm :true,
		resetForm :true,
		beforeSubmit:  checkForm,
		dataType: "json",
		type:"post",
		success : function(ret) {
			if(ret.msg==''){
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}},
					close: function() {
						//location=ret.data.url;
						if(ret.data.url==''){
							window.location.reload();
						}else{
							location=ret.data.url;
						}
					}
				}); 
				$("#msg").html("操作成功");
			}else{
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}}
				}); 
				$("#msg").html(ret.msg);
			}
		}
	};
	$("#message_sent_form").ajaxSubmit(options);
	return false;
}

function checkForm(){
	var err = "";
	if($("#receive_username").val()==''){
		err = "收信人为空";
	}else if($("#name").val()==''){
		err = "标题为空";
	}else if($("#content").val()==''){
		err = "内容为空";
	}else if($("#receive_username").val()=='admin'){
		err = "不能给系统发送信件";
	}
	if(err!=""){
		$('#dialog').dialog({
			modal:true,
			title:'系统提示',
			buttons:{"确定":function(){$(this).dialog("close");}}
		}); 
		$("#msg").html(err);
		return false;
	}else{
		$('#dialog').dialog({
			modal:true,
			title:'系统提示'
		}); 
		$("#msg").html("正在发送...");
		return true;
	}
	
}

</script>